package com.github.shiro.mapper;

import com.github.shiro.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Set;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ruiyanglee
 * @since 2020-07-23
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select distinct p.code" +
            "from tb_role r, tb_user u, tb_user_role ur,tb_role_permission rp, " +
            "tb_permission p" +
            "where r.id=ur.role_id and u.id = ur.user_id and rp.role_id = r.id " +
            "and rp.permission_id= p.id and u.username=#{username} ")
    Set<String> findPermissionsByUsername(String username);

    @Select("select distinct r.code" +
            "from tb_role r, tb_user u , tb_user_role ur" +
            "where r.id=ur.role_id and u.id=ur.user_id and u.username=#{username} ")
    Set<String> findRolesByUsername(String username);

}
